package com.mipo.iflytek.cycore.jinzhou.product;

import java.io.File;
import java.util.HashMap;
import java.util.List;

import cn.cycore.epdres.EpdResClient;
import cn.cycore.epdres.models.AuditStatusEnum;
import cn.cycore.epdres.models.CategoryModel;
import cn.cycore.epdres.models.ResourceBasicModel;
import cn.cycore.epdres.models.ResourceModel;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mipo.iflytek.cycore.jinzhou.FileMd5;


/**
 * cycore的资源服务
 * 
 * @author kitty
 * @date 2018年4月13日
 */
public class EpdResMain {
	
	private static EpdResClient epdResClient = null;
	
	
	/**
	 * 获取资源服务sdk客户端
	 */
	private static EpdResClient getResourceClient() {
		if (epdResClient == null) {
			//PropertiesConfiguration config = PropertiesConfigurationFactoryBean.getPropertiesConfiguration();
			//String appName = config.getString("usercenter.appname.default");
			//String appSecret = config.getString("usercenter.appsecret.default");
			//String serverUrl = config.getString("epdres.server.Url");
			String appName = "rrt_jinzhou";
			String appSecret = "695ed724b0553de7a711a0e1ffbb82c8";
			String serverUrl = "http://epdres.cycore.host";
			
//			String appName = "rrt_jinzhou";
//			String appSecret = "695ed724b0553de7a711a0e1ffbb82c8";
//			String serverUrl = "http://epdres.cloud.lnjzedu.gov.cn";
			
				
				
			epdResClient = new EpdResClient(appName, appSecret);
			epdResClient.setHost(serverUrl);
		}
		return epdResClient;
	}
	
	/**
	 * 资源文件存放在?
	 * 资源的元数据信息存在mongodb:172.31.12.20 27017 admin root/jinzhou@2017
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		///////////////////////////////////////////////////
//		ResourceModel resourceModel = new ResourceModel();
//		//相当于设置mongdb数据库的general start
//		resourceModel.setId("7d72fa3fc2804d769a18fc6e6064baa5");
//		resourceModel.setProductid("rrt_jinzhou");
//		resourceModel.setTitle("44444444444444.docx");
//		resourceModel.setLanguage("zh-CN");
//		resourceModel.setSource("UGC");
//		resourceModel.setExtension("docx");
//		resourceModel.setMd5(FileMd5.getMd5(new File("G:\\xxxxxxxxxx.xls")));
//		resourceModel.setLength(461125);
//		resourceModel.setDescription("");
//		resourceModel.setQuality("20");;
//		resourceModel.setCreator("jzsz02");;
//		resourceModel.setUploader("jzsz02");;
//		resourceModel.setModule("be6427c7bc90493fa16e4cac34e334bb");
//		resourceModel.setAction("分享到资源中心");
//		//相当于设置mongdb数据库的general end
//		//相当于设置mongdb数据库的properties
//		HashMap<String,String[]> properties = new HashMap<String,String[]>();
//		properties.put("grade", new String[]{"01"});
//		properties.put("subject", new String[]{"01"});
//		properties.put("volume", new String[]{"01"});
//		properties.put("publisher", new String[]{""});
//		properties.put("edition", new String[]{"01"});
//		properties.put("phase", new String[]{"03"});
//		properties.put("stage", new String[]{"01"});
//		properties.put("type", new String[]{"0100"});
//		properties.put("topic", new String[]{"08"});
//		properties.put("book", new String[]{"0101010101-412"});
//		properties.put("unit", new String[]{""});
//		properties.put("unit1", new String[]{"0101010101-412-14493"});
//		properties.put("unit2", new String[]{""});
//		properties.put("unit3", new String[]{""});
//		properties.put("unit4", new String[]{""});
//		properties.put("knowledge", new String[]{""});
//		properties.put("area", new String[]{""});
//		properties.put("province", new String[]{"500"});
//		properties.put("city", new String[]{"562"});
//		properties.put("district", new String[]{"564"});
//		properties.put("school", new String[]{"2300000001000071710"});
//		properties.put("source", new String[]{"04"});
//		properties.put("lang", new String[]{"160"});
//		properties.put("tag", new String[]{""});
//		properties.put("developer", new String[]{""});
//		properties.put("page", new String[]{""});
//		properties.put("topicKnowledge", new String[]{""});
//		properties.put("organization", new String[]{""});
//		resourceModel.setProperties(properties);
//		//相当于设置mongodb数据库的files
//		//resourceModel.setOriginalDescription("");
//		//HashMap<String, String> thumbnails = new HashMap<String, String>();
//		//thumbnails.put("106_80", "rrt_jinzhou/2018/04/04/10/10289fdc-0bd4-44f8-b134-b684112240ab_docx_size_106_80.jpg");
//		//thumbnails.put("254_190", "rrt_jinzhou/2018/04/04/10/10289fdc-0bd4-44f8-b134-b684112240ab_docx_size_254_190.jpg");
//		//resourceModel.setThumbnail(thumbnails);//缩略图
//		//resourceModel.setPreviewurl("");//预览地址
//		//相当于设置mongodb数据库的statistics
//		HashMap<String, Object> statistics = new HashMap<String, Object>();
//		statistics.put("downloadCount", "6");
//		resourceModel.setStatistics(statistics);
//		//相当于设置mongodb数据库的date
//		resourceModel.setCreatetime("");
//		resourceModel.setLastmodify("");
//		resourceModel.setUploadtime("");
//		//相当于设置mongodb数据库的lifecycle
//		HashMap<String, String> lifecycle = new HashMap<String, String>();
//		lifecycle.put("lifeStatus", "1");
//		lifecycle.put("securityStatus", "1");
//		lifecycle.put("auditStatus", "0");
//		resourceModel.setLifecycle(lifecycle);
//		ResourceBasicModel r = getResourceClient().getResource().addResource("G:\\xxxxxxxxxx.xls", resourceModel, AuditStatusEnum.OK);//上传资源资源网关
//		System.out.println(r.getMd5());
//		System.out.println(r.getResourceID());
		getType();
		
	}
	
	
	public static void booklibrary2(){
		// 查询资源服务获取列表
		HashMap<String, String> mapPhase = new HashMap<String, String>();// 创建map
		List<HashMap<String, String>> list = getResourceClient().getTree().getTreeNodes("booklibrary2", "phase", mapPhase);
		for (HashMap<String, String> li : list) {
			System.out.println(li);
		}
	}
	
	
	public static void res() {
		ResourceModel res=getResourceClient().getResource().getResourceInfo("7d72fa3fc2804d769a188a6e6064baa5");//获取资源信息
		System.out.println(res.getTitle()); // 舟山教学通问题记录2.docx
		String[] resources=res.getResources();//获取附属资源列表
		ResourceModel condition = new ResourceModel();
		condition.setTitle("123.docx");
		boolean bool = getResourceClient().getResource().updateResourceInfo("7d72fa3fc2804d769a188a6e6064baa5",condition); //更新资源
		System.out.println(bool); //true
	}
	
	/**
	 * 获取资源类型
	 */
	public static void getType() {
		List<JSONObject> grade = getResourceClient().getCategory().getCategoryValueList("grade");
		System.out.println(JSONArray.toJSON(grade));// [{"code":"01","name":"一年级"},{"code":"02","name":"二年级"},{"code":"03","name":"三年级"},{"code":"04","name":"四年级"},{"code":"05","name":"五年级"},{"code":"06","name":"六年级"},{"code":"07","name":"七年级"},{"code":"08","name":"八年级"},{"code":"09","name":"九年级"},{"code":"10","name":"高一"},{"code":"11","name":"高二"},{"code":"12","name":"高三"},{"code":"19","name":"高中"},{"code":"14","name":"小班"},{"code":"15","name":"中班"},{"code":"16","name":"大班"},{"code":"17","name":"学前综合"},{"code":"18","name":"课外"},{"code":"13","name":"演示"},{"code":"00","name":"其他"},{"code":"20","name":"职教一"},{"code":"21","name":"职教二"},{"code":"22","name":"职教三"}]
		List<JSONObject> type = getResourceClient().getCategory().getCategoryValueList("type");
		System.out.println(JSONArray.toJSON(type));// [{"code":"01","name":"一年级"},{"code":"02","name":"二年级"},{"code":"03","name":"三年级"},{"code":"04","name":"四年级"},{"code":"05","name":"五年级"},{"code":"06","name":"六年级"},{"code":"07","name":"七年级"},{"code":"08","name":"八年级"},{"code":"09","name":"九年级"},{"code":"10","name":"高一"},{"code":"11","name":"高二"},{"code":"12","name":"高三"},{"code":"19","name":"高中"},{"code":"14","name":"小班"},{"code":"15","name":"中班"},{"code":"16","name":"大班"},{"code":"17","name":"学前综合"},{"code":"18","name":"课外"},{"code":"13","name":"演示"},{"code":"00","name":"其他"},{"code":"20","name":"职教一"},{"code":"21","name":"职教二"},{"code":"22","name":"职教三"}]
		
		
	}
	
	
	
}
